//节流 
function throttled(fn,delay){
    let timer=null;
    let starttime=Date.now()
    return function(){
        let curTime=Date.now()//当前时间
        let remaining=delay-(curTime-starttime)//剩余时间
        let context=this
        let args=arguments
        clearTimeout(timer)
        if(remaining<=0){
            fn.apply(context,args)
            starttime=Date.now()
        }else{
            timer=setTimeout(fn,remaining)
        }
    }
}
//防抖 防抖在连续的事件，只需触发一次回调
function debounce(func,wait){
    let timeout 
    return function () {
        let context=this//保存this对象
        let args=arguments//拿到event对象
        clearTimeout(timeout)
        timeout=setTimeout(function(){
            func.apply(context,args)
        },wait)
    }
}